<script type="text/javascript" src="<?=PATH_URL.'static/js/admin/jquery.slugit.js'?>"></script>
<script type="text/javascript">
$(document).ready( function() {
	$("#titleVnAdmincp").slugIt({
		events: 'keyup blur',
		output: '#slugAdmincp',
		space: '-'
	});
});

function save(){
	var options = {
		beforeSubmit:  showRequest,  // pre-submit callback
		success:       showResponse  // post-submit callback
    };
	$('#contentViAdmincp').val(oEdit1.getHTMLBody());
	$('#contentEnAdmincp').val(oEdit2.getHTMLBody());
	$('#contentGrAdmincp').val(oEdit3.getHTMLBody());
	$('#frmManagement').ajaxSubmit(options);
}

function showRequest(formData, jqForm, options) {
	var form = jqForm[0];
	// if(form.titleAdmincp.value == '' || form.descAdmincp.value == '' || $('#contentAdmincp').val() == '<br>' || $('#contentAdmincp').val() == ''){
	// 	$('#txt_error').html('Please enter information!!!');
	// 	$('#loader').fadeOut(300);
	// 	show_perm_denied();
	// 	return false;
	// }
	if(form.titleVnAdmincp.value == ''){
		$('#loader').hide();
		alert('Bạn chưa nhập ngôn ngữ tiếng việt.');
		show_content('vn');
		$('input[name="titleVnAdmincp"], textarea[name="titleVnAdmincp"]').addClass('error-fr');
		scrollTo('#contentLang');
		return false;
	}
	if(form.titleEnAdmincp.value == ''){
		$('#loader').hide();
		alert('Bạn chưa nhập ngôn ngữ tiếng Anh.');
		show_content('en');
		$('input[name="titleEnAdmincp"], textarea[name="titleEnAdmincp"]').addClass('error-fr');
		scrollTo('#contentLang');
		return false;
	}
	if(form.titleGrAdmincp.value == ''){
		$('#loader').hide();
		alert('Bạn chưa nhập ngôn ngữ tiếng Đức.');
		show_content('gr');
		$('input[name="titleGrAdmincp"], textarea[name="titleGrAdmincp"]').addClass('error-fr');
		scrollTo('#contentLang');
		return false;
	}
}

function showResponse(responseText, statusText, xhr, $form) {
	if(responseText=='success'){
		location.href=root+"admincp/"+module+"/#/save";
	}

	if(responseText=='error-title-exists'){
		$('#txt_error').html('Title already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#titleAdmincp').focus();
		return false;
	}

	if(responseText=='error-slug-exists'){
		$('#txt_error').html('Slug already exists!!!');
		$('#loader').fadeOut(300);
		show_perm_denied();
		$('#slugAdmincp').focus();
		return false;
	}

	if(responseText=='permission-denied'){
		show_perm_denied();
	}
}

function show_content(lang){
	$('.w_content').hide();
	$('#'+lang).show();
        $('#img_'+lang).css('width','20px');
        if(lang=='vn'){
           $('#img_en').css('width','17px');
           $('#img_gr').css('width','17px');
        }
        else if(lang=='en'){
           $('#img_vn').css('width','17px');
           $('#img_gr').css('width','17px');
        }
        else{
           $('#img_vn').css('width','17px');
           $('#img_en').css('width','17px');
        }
}
</script>
<div class="gr_perm_error" style="display:none;">
	<p><strong>FAILURE: </strong><span id="txt_error">Permission Denied.</span></p>
</div>
<div class="table">
	<div class="head_table"><div class="head_title_edit"><?=$module?></div></div>
	<div class="clearAll"></div>

	<form id="frmManagement" action="<?=PATH_URL.'admincp/'.$module.'/save/'?>" method="post" enctype="multipart/form-data">
	<input type="hidden" value="<?=$id?>" name="hiddenIdAdmincp" />
	<div class="row_text_field_first">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Status:</td>
				<td class="right_text_field"><input <?php if(isset($result->status)){ if($result->status==1){ ?>checked="checked"<?php }}else{ ?>checked="checked"<?php } ?> type="checkbox" class="custom_chk" name="statusAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Slug:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->slug)) { print $result->slug; }else{ print '';} ?>" type="text" name="slugAdmincp" id="slugAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Order View:</td>
				<td class="right_text_field"><input value="<?php if(isset($result->order_view)) { print $result->order_view; }else{ print '';} ?>" type="text" name="order_viewAdmincp" id="order_viewAdmincp" /></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Parent:</td>
				<td class="right_text_field">
					<?php if(isset($category)) : ?>
						<select name='parentIdAdmincp'>
							<option value='0'>[ Menu ]</option>
							<?php echo $category; ?>
						</select>
					<?php endif; ?>
				</td>
			</tr>
		</table>
	</div>

	<div class="row_text_field">
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td class="left_text_field">Image:</td>
				<td class="right_text_field"><input type="file" name="fileAdmincp[image]" /><?php if(isset($result->image)){ if($result->image!=''){ ?> - <a class="fancyboxClick" href="<?=PATH_URL.DIR_UPLOAD_NEWS.$result->image?>">Review</a><?php }} ?></td>
			</tr>
		</table>
	</div>

	<div class="row_text_field" id='contentLang'>
		<table cellspacing="0" cellpadding="0" border="0" width="100%">
			<tr>
				<td style="text-align:center;">
          <a href="javascript:void(0)" onclick="return show_content('vn')"><img src="<?=PATH_URL?>static/images/icon/icon_vn.png" id="img_vn" width="20" /></a>
					<a href="javascript:void(0)" onclick="return show_content('en')"><img src="<?=PATH_URL?>static/images/icon/icon_usa.png" id="img_en" /></a>
					<a href="javascript:void(0)" onclick="return show_content('gr')"><img src="<?=PATH_URL?>static/images/icon/icon_germany.png" id="img_gr" /></a>
				</td>
			</tr>
		</table>
	</div>

	<div id="vn" class="w_content">
		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Title Vi:</td>
					<td class="right_text_field"><input value="<?php if(isset($result->title_vi)) { print $result->title_vi; }else{ print '';} ?>" type="text" name="titleVnAdmincp" id="titleVnAdmincp" /></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Description Vi:</td>
					<td class="right_text_field"><textarea name="descVnAdmincp" cols="" rows="8"><?php if(isset($result->description_vi)) { print $result->description_vi; }else{ print '';} ?></textarea></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Content Vi:</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="contentViAdmincp" id="contentViAdmincp" cols="" rows="8"><?php if(isset($result->content_vi)) { print $result->content_vi; }else{ print '';} ?></textarea>
						<script type="text/javascript">
							var oEdit1 = new InnovaEditor("oEdit1");
							oEdit1.width = "100%";
							oEdit1.cmdAssetManager="modalDialogShow('"+root+"static/editor/assetmanager/assetmanager.php',640,445);";
							oEdit1.REPLACE("contentViAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>

	</div><!-- end #vn -->

	<div id="en" class="w_content" style="display:none;">

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Title En:</td>
					<td class="right_text_field"><input value="<?php if(isset($result->title_en)) { print $result->title_en; }else{ print '';} ?>" type="text" name="titleEnAdmincp" id="titleEnAdmincp" /></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Description En:</td>
					<td class="right_text_field"><textarea name="descEnAdmincp" cols="" rows="8"><?php if(isset($result->description_en)) { print $result->description_en; }else{ print '';} ?></textarea></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Content En:</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="contentEnAdmincp" id="contentEnAdmincp" cols="" rows="8"><?php if(isset($result->content_en)) { print $result->content_en; }else{ print '';} ?></textarea>
						<script type="text/javascript">
							var oEdit2 = new InnovaEditor("oEdit2");
							oEdit2.width = "100%";
							oEdit2.cmdAssetManager="modalDialogShow('"+root+"static/editor/assetmanager/assetmanager.php',640,445);";
							oEdit2.REPLACE("contentEnAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<div id="gr" class="w_content" style="display:none;">

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Title Gr:</td>
					<td class="right_text_field"><input value="<?php if(isset($result->title_gr)) { print $result->title_gr; }else{ print '';} ?>" type="text" name="titleGrAdmincp" id="titleGrAdmincp" /></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Description Gr:</td>
					<td class="right_text_field"><textarea name="descGrAdmincp" cols="" rows="8"><?php if(isset($result->description_gr)) { print $result->description_gr; }else{ print '';} ?></textarea></td>
				</tr>
			</table>
		</div>

		<div class="row_text_field">
			<table cellspacing="0" cellpadding="0" border="0" width="100%">
				<tr>
					<td class="left_text_field">Content Gr:</td>
					<td class="right_text_field" style="padding-right: 0px;">
						<textarea name="contentGrAdmincp" id="contentGrAdmincp" cols="" rows="8"><?php if(isset($result->content_gr)) { print $result->content_gr; }else{ print '';} ?></textarea>
						<script type="text/javascript">
							var oEdit3 = new InnovaEditor("oEdit3");
							oEdit3.width = "100%";
							oEdit3.cmdAssetManager="modalDialogShow('"+root+"static/editor/assetmanager/assetmanager.php',640,445);";
							oEdit3.REPLACE("contentGrAdmincp");
						</script>
					</td>
				</tr>
			</table>
		</div>
	</div>
	</form>
</div>
